package com.zlx.learn.kown.service.impl;

import com.zlx.learn.kown.entity.Ebook;
import com.zlx.learn.kown.entity.EbookExample;
import com.zlx.learn.kown.mapper.EbookMapper;
import com.zlx.learn.kown.req.EbookReq;
import com.zlx.learn.kown.resp.EbookResp;
import com.zlx.learn.kown.service.EbookService;
import com.zlx.learn.kown.util.CopyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;
@Service
public class EbookServiceImpl implements EbookService {
    @Resource
    private EbookMapper ebookMapper;

    @Override
    public List<EbookResp> list(EbookReq ebookReq) {
        EbookExample ebookExample  = new EbookExample();
        // 内部类，类似sql的where
        EbookExample.Criteria criteria = ebookExample.createCriteria();
        // 设置条件
        criteria.andNameLike("%" + ebookReq.getName() + "%");
        List<Ebook> list = ebookMapper.selectByExample(ebookExample);

        // 将Ebook列表拷贝到ebookResp列表中
        return CopyUtil.copyList(list,EbookResp.class);
    }
}
